<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/adminHead.jsp"%>
<script type="text/javascript">
    var _this = this;
    $(function () {
        _this.tbl_menu = tableSync('tbl_menu');
        init();
        getMenuList();
    });
    var markerSetting = {
            paging: {}
        };
    function init() {
        markerSetting.paging.page      = '1';
        markerSetting.paging.totalPage = '<c:out value="${totalPage}"/>';
        markerSetting.paging.nowSeq    = 1;
        markerSetting.paging.boardType = $("#boardType").val();
    }
    function getMenuList() {
        var url = '/admin/getAdminMenuList.json';
        var param = markerSetting.paging;
        AjaxPost(url, param, function (data) {
            $.each(data.menuTbl, function (index, value) {
                value.useFlag = value.useFlag * 1 == 1 ? '사용' : '미사용';
            });
            _this.tbl_menu.tableAutoSync(data.menuTbl);
            markerSetting.paging.totalPage = data.totalPage;
            makePaging();
        });
    }
    function getSearchBoardList() {
        markerSetting.paging.searchType = $("select[name=searchType]").val();
        markerSetting.paging.searchName = $("#searchName").val();
        getMenuList();
    }
    function makePaging() {
        $('#pagenation').html("");
        var totalPage = markerSetting.paging.totalPage;
        var nowPage = markerSetting.paging.page;
        var html = '';
        var setFunctionName = '';
        var index = (nowPage - 10);
        var indexCount = 0;
        var endPage = totalPage / 10;
        if (totalPage % 10 > 0) {
            endPage = endPage + 1;
        }
        if (index > 1) {
            html += '<a onclick="changePaging(1,\'before\'' + ')" onFocus=this.blur()><img src="${imgUrl }/btn_first.jpg"/ alt=처음 align=absmiddle style="/cursor:hand;/"></a>';
            html += '<a onclick="changePaging(' + index + ',\'before\'' + ')" onFocus=this.blur()><img src="${imgUrl }/btn_prev.jpg"/  alt=이전 align=absmiddle style="/cursor:hand;/"></a>&nbsp;&nbsp;';
        }
        for (; index <= endPage; index++) {
            if ((index) == nowPage) {
                setFunctionName = '';
            } else {
                setFunctionName = ' onclick="changePaging(' + index + ')"';
            }
            if (index > 0) {
                if (index == nowPage) {
                    html += '<a ' + setFunctionName + '><b>' + index + '</b></a>&nbsp;';
                } else {
                    html += '<a ' + setFunctionName + ' style=cursor:hand;>' + index + '</a>&nbsp;';
                }
                indexCount++;
            }
            if (indexCount > 9) {
                html += '<a onclick="changePaging(' + index + ',\'after\'' + ')" onFocus=this.blur()><img src="${imgUrl }/btn_next.jpg"/  alt=다음 align=absmiddle style="/cursor:hand;/"></a>';
                html += '<a onclick="changePaging(' + totalPage + ',\'after\'' + ')" onFocus=this.blur()><img src="${imgUrl }/btn_last.jpg"/  alt=맨끝 align=absmiddle style="/cursor:hand;/"></a>';
                break;
            }
        }
        $('#pagenation').html(html);
    }
    function changePaging(index, option) {
        logs('markerSetting.paging.totalPage = ' + markerSetting.paging.totalPage);
        if (option == null) {
            logs(', index = ' + index);
            markerSetting.paging.page  = index;
            markerSetting.paging.start = 0;
            markerSetting.paging.end   = 0;
            getMenuList();
        } else {
            if (option == 'before') {
                var next = index - 9;
                while (next <= 0) {
                    next++;
                }
                logs('next = ' + next + ', index = ' + index);
                markerSetting.paging.page  = next;
                markerSetting.paging.start = 0;
                markerSetting.paging.end   = 0;
                getMenuList();
            } else if (option == 'after') {
                var next = index + 9;
                while (next >= (markerSetting.paging.totalPage / 10) + 1) {
                    next--;
                }
                logs('next = ' + next + ', index = ' + index);
                markerSetting.paging.page  = next;
                markerSetting.paging.start = 0;
                markerSetting.paging.end   = 0;
                getMenuList();
            }
        }
    }
    var modifyMenu = function (td) {
            var $tr = $(td).parent();
            var menuIndex = $tr.find('#menuIndex').val();
            location.replace("/admin/adminMenuWrite?menuIndex=" + menuIndex);
        };

    function hitEnterKey(e){
    	  if(e.keyCode == 13){
    		  search();
    		  return false;
    	  }
    } 
    
    var search = function(){
    	var searchValue = $('#search_word').val(); 
    		if($('#search_type').val() == 'useFlag'){
    			if(searchValue == '사용'){
    				searchValue = 1;
    			}else if(searchValue == '미사용'){
    				searchValue = 0;
    			}else{
    				alert('사용/미사용 으로 입력해주세요.');
    				return;
    			}
    		}
    		markerSetting.paging[$('#search_type').val()]=searchValue;
    		getMenuList();
    		markerSetting.paging[$('#search_type').val()]=undefined;
    }
    
    function goAdminBoardListMain(type, menuType) {
    		$("#paramMenuIndex").val(type);
    		$("#paramMenuType").val(menuType);
    		var url;
    		
    		if (menuType == 0) {
    			url = "/admin/adminBoardMain";
    		} else {
    			url = "/admin/adminBoard2Main";
    		}
    					
    		$("#frm").attr("action", url);
    		$("#frm").submit();
    		
      }
    var goAdminMenuList = function(){
    	location.replace("/admin/adminMenuMain");
    };	
</script>
<TR>
    <TD height="%" valign="top">
        <TABLE border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
            <TBODY>
                <TR>
                    <TD align="right" height="%" valign="top" width="186">
                        <TABLE border="0" cellpadding="0" cellspacing="0" height="100%" width="176">
                            <TBODY>
                                <TR>
                                    <TD height="53">
                                        <IMG src="${imgUrl}/left_top_title.gif"></TD>
                                    </TR>
                                    <TR>
                                        <TD background="${imgUrl}/left_bg.gif" height="%" style="padding: 5px 0px 0px 5px;" valign="top">
                                            <LINK href="${imgUrl}/admin.css" rel="stylesheet" type="text/css">
                                                <TABLE border="0" cellpadding="0" cellspacing="0" style="margin-top: 10px;" width="150">
                                                    <TBODY>                                                  
                                                    <c:forEach var = "menu" items="${menuList}">					
														<tr>
															<td height="25"><img src="${imgUrl}/left_icon.gif" border="0" align="absmiddle"/>
																<a class="leftmenu" href="javascript:goAdminBoardListMain(<c:out value="${menu.menuIndex}" />, <c:out value="${menu.menuType}" />)"><c:out value="${menu.menuName}" /></a>
															</td>
														</tr>				
													</c:forEach>     
                                                        <tr>
                                                            <td height="25"><img align="absmiddle" border="0" src="${imgUrl}/left_icon.gif"/><a class="leftmenu_b" href="#">&nbsp;메뉴관리</a></td>
                                                        </tr>
                                                    </TBODY>
                                                </TABLE>
                                            </TD>
                                        </TR>
                                    </TBODY>
                                </TABLE>
                            </TD>
                            <TD align="right" style="padding: 20px 10px 0px 0px;" valign="top" width="%">
                                <TABLE border="0" cellpadding="0" cellspacing="0" width="97%">
                                    <TBODY>
                                        <TR>
                                            <TD align="left" background="${imgUrl}/title_bg.gif" class="admin_title" valign="middle"><IMG align="absmiddle" src="${imgUrl}/title_icon.gif">메뉴관리</TD></TR>
                                            <TR>
                                                <TD height="20">&nbsp;</TD></TR>
                                            <TR>
                                                <TD>
                                                    <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                                                        <TBODY>
                                                            <TR>
                                                                <TD>
                                                                    <TABLE bgcolor="#d9d9d9" border="0" cellpadding="0" cellspacing="1" width="100%">
                                                                        <TBODY>
                                                                            <TR>
                                                                                <TD bgcolor="#3f8bc9" colspan="7" height="1"></TD>
                                                                            </TR>
                                                                            <TR>
                                                                                <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="11%">정렬순서</TD>
                                                                                <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="*">메뉴명</TD>
                                                                                <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="20%">사용여부</TD>
                                                                            </TR>
                                                                        </tbody>
                                                                    </table>
                                                                    <TABLE bgcolor="#d9d9d9" border="0" cellpadding="0" cellspacing="1" id="tbl_menu" width="100%">
                                                                        <TBODY>
                                                                            <TR>
                                                                                <TD align="center" bgcolor="#ffffff" class="list_dark" id="morder" width="11%">3</TD>
                                                                                <TD align="center" bgcolor="#ffffff" class="list_dark" id="menuName" onclick="modifyMenu(this)" style="cursor: hand" width="*">알당</TD>
                                                                                <TD align="center" bgcolor="#ffffff" class="list_dark" id="useFlag" width="20%">알당</TD>
                                                                                <td width="0">
                                                                                    <input id="menuIndex" name="menuIndex" type="hidden"/>
                                                                                </td>
                                                                            </TR>
                                                                        </TBODY>
                                                                    </TABLE>
                                                                </TD>
                                                            </TR>
                                                            <TR>
                                                                <TD align="right" colspan="7" height="30" valign="bottom">
                                                                    <A href="/admin/adminMenuWrite">
                                                                        <IMG src="${imgUrl}/btn_write.gif"></A>
                                                                    </TD>
                                                                </TR>
                                                                <TR>
                                                                    <TD align="center" colspan="7" height="35" valign="middle">
                                                                        <div id="pagenation"></div>
                                                                    </TD>
                                                                </TR>
                                                                <TR>
                                                                    <TD align="center" colspan="7">
                                                                            <FORM method="post" name="fsearch" style="margin: 0px;"  onkeydown="hitEnterKey(event)" onsubmit="return false;">
                                                                        <TABLE border="0" cellpadding="0" cellspacing="0">
                                                                                <TBODY>
                                                                                    <TR>
                                                                                        <TD align="middle" style="padding: 3px 0px 0px 5px;" valign="middle">
                                                                                            <SELECT class="inputText" id="search_type" name="search_type">
                                                                                            	<OPTION selected value="menuName">메뉴명</OPTION>
                                                                                                <OPTION value="useFlag">사용여부</OPTION>
                                                                                            </SELECT>
                                                                                            <INPUT class="inputText" maxlength="25" name="search_word" id="search_word" size="30" type="text" /></TD>
                                                                                            <TD align="right" style="padding-left: 5px;" valign="middle">
                                                                                                <INPUT align="absmiddle" hspace="3" src="${imgUrl}/n_search.gif" style="cursor: hand;" type="image" onclick="search()"></TD>
                                                                                            </TR>
                                                                                        </TBODY>
                                                                                    </TABLE>
                                                                        </FORM>
                                                                                </TD>
                                                                            </TR>
                                                                        <TR>
                                                                            <TD>&nbsp;</TD></TR>
                                                                    </TBODY>
                                                                </TABLE>
                                                            </TD>
                                                        </TR>
                                                    </TBODY>
                                                </TABLE>
                                            </TD>
                                        </TR>
                                    </TBODY>
                                </TABLE>
                            </TD>
                        </TR>
                    </TBODY>
                </TABLE>
<form style="display:none;" id="frm" name="frm" method="post">
	<input type="hidden" name="menuIndex" id="paramMenuIndex" value="${menu.menuIndex}">
	<input type="hidden" name="menuType" id="paramMenuType" value="${menu.menuType}">	
</form>
            </BODY>
        </HTML>